/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.hanze.shoestring.dao.impl;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author alex
 */
public class BasePersistence {

    protected EntityManagerFactory emf;
    protected EntityManager em;

    public void open() {
        if (emf == null || !emf.isOpen()) {
            emf = Persistence.createEntityManagerFactory("ShoestringJPAPU");
        }
        
        if (em == null || !em.isOpen()) {
            em = emf.createEntityManager();
        } 
    }

    protected void close() {
        em.close();
        emf.close();
    }
}
